<?php
namespace services;
use Sanyc\Aliyun\AliyunEmail;
use think\Exception;

class MailAliyun implements SmsInterface
{
    private $config = '';

    public function __construct ($config = array())
    {
        if ($mail_config = config('mail')) {
            $config = array_merge($mail_config, $config);
        }        
        
        $this->config = $config;
    }
    /**
     * 发送验证码
     * @param  string $mail        邮箱
     * @param  numeric  $code      验证码
     * @param  int $active_time    有效时间
     * @return bool                true/false
     */
    public function sendCaptcha ($mail, $code, $active_time)
    {
        $bodys = lang('captcha_body',['code' => $code,'active_time' => $active_time]);
        try {
            return AliyunEmail::init($this->config)->send($mail, lang('site_name'), $bodys) ? true : false;
        } catch (\Exception $e) {}

        return false;
    }
    /**
     * 发送订单信息
     * @param  [type] $mail [description]
     * @param  [type] $body [description]
     * @return [type]       [description]
     */
    public function sendOrder ($mail, $body)
    {
        return true;
    }
    /**
     * 发送信息
     * @param  [type] $mail [description]
     * @param  [type] $body [description]
     * @return [type]       [description]
     */
    public function sendMessage($mail, $body)
    {
        try {
            AliyunEmail::init($this->config)->send($mail, lang('site_name'), $body);
        } catch (\Exception $e) {}
        
        date_default_timezone_set(\think\Config::get('default_timezone'));

        return true;
    }
    public function sendSearch($mail, $body)
    {
        try {
            return AliyunEmail::init($this->config)->send($mail, lang('site_name'), $body) ? true : false;
        } catch (\Exception $e) {}

        return false;
    }
    public function sendJm($body, $mail = '')
    {
        try {
            return AliyunEmail::init($this->config)->send($mail, '加盟咨询', $body) ? true : false;
        } catch (\Exception $e) {}

        return false;
    }
}